package com.lanou.moving.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lanou.moving.R;
import com.lanou.moving.entity.MVClassify;

import java.util.List;

/**
 * Created by 梁树珍 on 15/11/4.
 */
public class MVClassifyAdapter extends BaseAdapter{
    private Context context;
    private List<MVClassify.DataEntity.SubTypeEntity> typeEntities;
    private int typeId;

    public MVClassifyAdapter(Context context, List<MVClassify.DataEntity.SubTypeEntity> typeEntities) {
        this.context = context;
        this.typeEntities = typeEntities;
    }

    @Override
    public int getCount() {
        return typeEntities == null ? 0 : typeEntities.size();
    }

    @Override
    public Object getItem(int position) {
        return typeEntities == null ? null : typeEntities.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.song_list_classify, null);
            holder = new ViewHolder();
            holder.song_list_item = (TextView) convertView.findViewById(R.id.song_list_item);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        typeId = typeEntities.get(position).getId();
        holder.song_list_item.setText(typeEntities.get(position).getName());
        return convertView;
    }
    private class ViewHolder{
        private TextView song_list_item;
    }

    public int getTypeId() {
        return typeId;
    }

    public void setTypeId(int typeId) {
        this.typeId = typeId;
    }
}
